/*  
 *  ------ [802_07] - energy scan  -------- 
 *  
 *  Explanation: This program shows how to scan all XBee channels
 *  in order to show the energy level of each channel
 *  
 *  Copyright (C) 2012 Sundaram Technologies
 *  http://makesure.org 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details. 
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 *  
 *  Version:           0.1 
 *  Design:            David Gascón 
 *  Implementation:    Yuri Carmona
 */

#include <MakeSureFrame.h>
#include <MakeSureXBee802.h>


void setup()
{ 
  // Init Xbee
	xbee802.ON();
    Serial.begin(9600);
    Serial.println("Sundaram Technologies");
}
void loop()
{ 

  // set the list of channels to scan as a Bitmap. 
  // 0xFFFF scan all possible channels
  xbee802.setScanningChannels(0xFF,0xFF); 
  
  // get the maximal energy on each scanned channel
  xbee802.setDurationEnergyChannels(2);

  // print information
  printEnergyChannel();

}  



/*
*  printEnergyChannel 
*
*  This function prints all stored energy 
*  for each channel in units of dBm
*/
void printEnergyChannel()
{
  Serial.print("\n\n----------------------");
  Serial.print("\nEnergy Scan (dBm)");
  Serial.print("\n----------------------");
  
  Serial.print("\nchannel 0x0B: ");
  Serial.print(xbee802.energyChannel[0]*(-1),DEC);
  
  Serial.print("\nchannel 0x0C: ");
  Serial.print(xbee802.energyChannel[1]*(-1),DEC);
  
  Serial.print("\nchannel 0x0D: ");
  Serial.print(xbee802.energyChannel[2]*(-1),DEC);
  
  Serial.print("\nchannel 0x0E: ");
  Serial.print(xbee802.energyChannel[3]*(-1),DEC);
  
  Serial.print("\nchannel 0x0F: ");
  Serial.print(xbee802.energyChannel[4]*(-1),DEC);
  
  Serial.print("\nchannel 0x10: ");
  Serial.print(xbee802.energyChannel[5]*(-1),DEC);
  
  Serial.print("\nchannel 0x11: ");
  Serial.print(xbee802.energyChannel[6]*(-1),DEC);
  
  Serial.print("\nchannel 0x12: ");
  Serial.print(xbee802.energyChannel[7]*(-1),DEC);
  
  Serial.print("\nchannel 0x13: ");
  Serial.print(xbee802.energyChannel[8]*(-1),DEC);
  
  Serial.print("\nchannel 0x14: ");
  Serial.print(xbee802.energyChannel[9]*(-1),DEC);
  
  Serial.print("\nchannel 0x15: ");
  Serial.print(xbee802.energyChannel[10]*(-1),DEC);
  
  Serial.print("\nchannel 0x16: ");
  Serial.print(xbee802.energyChannel[11]*(-1),DEC);
  
  Serial.print("\nchannel 0x17: ");
  Serial.print(xbee802.energyChannel[12]*(-1),DEC);
  
  Serial.print("\nchannel 0x18: ");
  Serial.print(xbee802.energyChannel[13]*(-1),DEC);
  
  Serial.print("\nchannel 0x19: ");
  Serial.print(xbee802.energyChannel[14]*(-1),DEC);
  
  Serial.print("\nchannel 0x1A: ");
  Serial.print(xbee802.energyChannel[15]*(-1),DEC); 
  
}



